Skip to content

use system adb/collector when available, extract bundled assets to temp dir#81

Open
besendorf wants to merge 2 commits intomainfrom
fix/system-install-assets
Open

use system adb/collector when available, extract bundled assets to temp dir#81
besendorf wants to merge 2 commits intomainfrom
fix/system-install-assets

Conversation

@besendorf
Copy link
Collaborator

  • assets: replace DeployAssets()/CleanAssets() with DeployAssetsToDir(dir) so callers control where binaries land and cleanup is simply os.RemoveAll.

  • adb (all platforms): check PATH for adb first; only extract the bundled binary when no system adb is found, and extract it into os.MkdirTemp instead of next to the executable (which may be /usr/bin or read-only). Store the temp dir in ADB.TmpAssetsDir for later cleanup.

  • adb: add ADB.Cleanup() that removes TmpAssetsDir; it is a no-op when the system adb was used and nothing was extracted.

  • collector: before reading from the embedded assets, check the ANDROIDQF_COLLECTOR_DIR environment variable; if set and readable, use those binaries instead. Distro packagers can point this at /usr/lib/androidqf/android-collector/; portable-binary users get the embedded fallback automatically.

  • acquisition: replace assets.CleanAssets() with adb.Client.Cleanup().

Addresses the issues raised in mvt-project/androidqf#79 without breaking the portable-binary use case.

…to temp dir

- assets: replace DeployAssets()/CleanAssets() with DeployAssetsToDir(dir)
  so callers control where binaries land and cleanup is simply os.RemoveAll.

- adb (all platforms): check PATH for adb first; only extract the bundled
  binary when no system adb is found, and extract it into os.MkdirTemp
  instead of next to the executable (which may be /usr/bin or read-only).
  Store the temp dir in ADB.TmpAssetsDir for later cleanup.

- adb: add ADB.Cleanup() that removes TmpAssetsDir; it is a no-op when
  the system adb was used and nothing was extracted.

- collector: before reading from the embedded assets, check the
  ANDROIDQF_COLLECTOR_DIR environment variable; if set and readable, use
  those binaries instead.  Distro packagers can point this at
  /usr/lib/androidqf/android-collector/; portable-binary users get the
  embedded fallback automatically.

- acquisition: replace assets.CleanAssets() with adb.Client.Cleanup().

Addresses the issues raised in #79 without breaking
the portable-binary use case.
@besendorf besendorf requested a review from tesitura March 18, 2026 14:20
Copy link
Contributor

@tesitura tesitura left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. One thing worth noting is that encrypted zip output path and key.txt lookup still use GetExecutableDirectory() in:

cwd := saveRuntime.GetExecutableDirectory()
keyFilePath := filepath.Join(cwd, "key.txt")

outputPath := filepath.Join(cwd, encFileName)

cwd := saveRuntime.GetExecutableDirectory()
keyFilePath := filepath.Join(cwd, "key.txt")

zipFilePath := filepath.Join(cwd, zipFileName)

I believe is worth aligning those to the same base path in a followup.

@kpcyrd
Copy link

kpcyrd commented Mar 24, 2026

How would you feel about using build tags123 for this?

They'd be defined like:

//go:build foo

at the top of a file and would allow for something like:

# normal build
go build

# build with tag enabled
go build -tags foo

So for "normal" builds everything stays the same, but one could optionally opt-out of assets/ being used (avoiding an error if the folder doesn't exist when the build starts). I can try to prepare a pull request for this.

Footnotes

  1. https://pkg.go.dev/go/build

  2. https://www.digitalocean.com/community/tutorials/customizing-go-binaries-with-build-tags

  3. https://stackoverflow.com/questions/15214459/how-to-properly-use-build-tags/67946874#67946874

@besendorf
Copy link
Collaborator Author

I think we can even have both solutions. Use the adb from Path if available still might make sense, but using build tags also makes sense so you can have smaller binaries for distros.
I am unsure which adb is newer usually the bundles one or packaged one.
There's probably also a lot of Debian's where we would prefer to use the bundled adb.
@tesitura ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants